﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VxiServer
{
    public sealed class ClientManagement
    {
        private static readonly ClientManagement singleton = new ClientManagement();  // eager

        static ClientManagement() { }

        private ClientManagement() { }

        public static ClientManagement GetInstance()
        {
            return singleton;
        }

        private static volatile Dictionary<string, ClientUser> userList = new Dictionary<string, ClientUser>();

        public static void AddClient(string ipAddress, ClientUser user)
        {
            if (userList.ContainsKey(ipAddress))
            {
                userList[ipAddress] = user;
            }
            else
            {
                userList.Add(ipAddress, user);
            }
        }


        public static ClientUser GetClient(string ipAddress)
        {
            if (userList.ContainsKey(ipAddress))
            {
                return userList[ipAddress];
            }
            return null;
        }
    }
}
